<?php
/**
 * 验证码
 * @copyright	http://www.easymvc.com
 * @author 		光哥 <439884988@qq.com>
 * @version		1.0 - 2012-06-29
 * @package		Lib
 */
if(!defined('EASYMVC')) {
	exit('Access Denied');
}
define('CAP_DIR',EXTENDPATH.'captcha'.DS);
require CAP_DIR.'captcha.class.php';

/**
 * 验证码
 */
class Lib_Extend_Captcha extends Captcha{
	public function __construct(){
	}
	public static function getInstance(){
		static $obj;
		if(!$obj) {
			$obj = new self();
		}
		return $obj;
	}
	/**
	 * 初始化
	 */
	public function init(){
		/*
		 *****CONFIGURATION STARTS*****
		*/
		//Background Image
		$config['BackgroundImage'] = "white.png";
		
		//Background Color- HEX
		$config['BackgroundColor'] = "FFFC00";
		
		//image height - same as background image
		$config['Height']=35;
		
		//image width - same as background image
		$config['Width']=120;
		
		//text font size
		$config['Font_Size']=26;
		
		//text font style Mosaicleaf086.ttf
		$config['Font']= CAP_DIR."A_Sensible_Armadillo.ttf";
		//$config['Font']= CAP_DIR."Mosaicleaf086.ttf";
		//text angle to the left
		$config['TextMinimumAngle']=15;
		
		//text angle to the right
		$config['TextMaximumAngle']=45;
		
		//Text Color - HEX
		$config['TextColor']='000000';
		
		//Number of Captcha Code Character
		$config['TextLength']=4;
		
		//Background Image Transparency
		$config['Transparency']=50;
		
		/*
		 *******CONFIGURATION ENDS******
		*/
		
		//Create a new instance of the captcha
		parent::captcha($config);
		
		Lib_Session::getInstance()->set("captcha_code",$this->Code);
		//Save the code as a session dependent string
		//$Lib_['captcha_code'] = $this->Code;
	}
	/**
	 * 校验验证码
	 * @param string $captcha
	 * @return boolean
	 */
	public function checkCaptcha($captcha){
		if(empty($captcha)) return false;
		$_captcha = Lib_Session::getInstance()->get("captcha_code");
		if(empty($_captcha)) return false;
		if(strtolower($captcha) == strtolower($_captcha)) {
			Lib_Session::getInstance()->del("captcha_code");
			return true;
		}
		return false;
		
	}
	
}